// components/shop-cate/index.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        show: {
            type: Boolean,
            default: false
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        list: [],
        curObj: null
    },
    created: function(){
        this.getList();
    },
    /**
     * 组件的方法列表
     */
    methods: {
        //获取分类
        getList: function(n) {
            wx.$http({
                load: true,
                url: `/business/classify-list`,
                method: 'get',
                data: {},
            }).then((res) => {
                let arr = res.data;
                this.setData({
                    list: arr
                })
            })
        },
        //选中分类
        selectObj: function(e) {
            let {curObj} = this.data;
            let obj = e.currentTarget.dataset.obj;
            if(curObj){
                this.setData({
                    curObj: obj.id == curObj.id?null:obj
                })
            }else{
                this.setData({
                    curObj: obj
                })
            }
        },
        //关闭
        close: function() {
            this.triggerEvent('confirm');  
        },
        //保存分类
        save: function() {
            let {curObj} = this.data;
            this.triggerEvent('confirm',{change: true, curObj:curObj});  
        }
    }
})